/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.yonsei.iwb.smarttv.querygraph;

import com.hp.hpl.jena.rdf.model.Resource;
import edu.yonsei.iwb.smarttv.model.ResourceNode;
import edu.yonsei.iwb.smarttv.model.measure.WeightModel;
import java.util.*;

/**
 *
 * @author Onlyjiny
 */
public class QueryCombinationSet extends Vector<QueryCombination> {
    
    /**
     * QueryCombinationSet을 점수 순으로 정렬
     * @param prwm user prefered resource attached weight model
     */
    public void orderByScore(WeightModel prwm){
        for (int i = 0; i < this.size(); i++) {
            QueryCombination qc = this.get(i);
            qc.setScore(prwm);
        }
                
        double[] d = new double[this.size()];
        QueryCombination[] qc = new QueryCombination[this.size()];
        int index = 0;
        for (int i = 0; i < this.size(); i++) {
            d[index] = this.get(i).getScore();
            qc[index] = this.get(i);
            index++;            
        }
        for (int i = 0; i < d.length-1; i++) {
            double temp;
            QueryCombination temQc;
            for (int j = 1; j < d.length; j++) {
                if(d[j-1] > d[j]){
                    temp = d[j-1];
                    d[j-1] = d[j];
                    d[j] = temp;
                    
                    temQc = qc[j-1];
                    qc[j-1] = qc[j];                    
                    qc[j] = temQc;
                }
            }
        }
        
        this.clear();
        for (int i = 0; i < qc.length; i++) {
            QueryCombination tempQC = qc[i];
            this.add(tempQC);
        }
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append("[\n");
        for (int i = 0; i < this.size(); i++) {
            sb.append(this.get(i).toString());
            if (i != (this.size() - 1)) {
                sb.append(",\n");
            }
        }
        sb.append("\n]\n");
        return sb.toString();
    }
}
